package estate;

public class Comment {

	private Long commentId;
	private String title;
	private String content;
	private boolean accepted;
	private boolean deleted;
	private String cause;
	private Estate estate;
	private User user;

	static private Long commentsNumber = new Long(0);


	public static Comment newComment(String title, String content, User user, Estate estate) {

        Comment comment = new Comment();

		++commentsNumber;
		comment.commentId = commentsNumber;

        comment.title = title;
        comment.content = content;
        comment.user = user;
        comment.estate = estate;

        comment.accepted = false;
        comment.deleted = false;
        comment.cause = null;

        return comment;
    }

	@Override
	public boolean equals(Object cmp)
	{
		if (cmp instanceof Comment)
		{
			Comment cmn = (Comment)cmp;
			if (!this.commentId.equals(cmn.commentId)) {return false;}
			if (!this.title.equals(cmn.title)) {return false;}
			if (!this.content.equals(cmn.content)) {return false;}
			if (!this.user.equals(cmn.user)) {return false;}
			if (!this.estate.equals(cmn.estate)) {return false;}
			if (!this.content.equals(cmn.content)) {return false;}
			return true;
		} else {
			return false;
		}
	}

	@Override
	public int hashCode()
	{
		return 11 + 67 * (user.hashCode() + estate.hashCode() + content.hashCode() + commentId.intValue());
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("id:" + commentId.toString() + ';');
		sb.append("tytul:" + title + ';');
		sb.append("tresc:" + content + ';');
		sb.append("uzytkownik:" + user.toString() + ';');
		sb.append("oferta:" + estate.toString() + ';');
		sb.append("zaakceptowany:" + (accepted ? "tak" : "nie") + ';');
		sb.append("usuniety:" + (deleted ? "tak" : "nie"));
		if(deleted) {
			sb.append(";powod:" + cause);
		}

		return sb.toString();
	}

	public Long getId() {
		return commentId;
	}

	public void setId(Long id) {
		commentId = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public boolean isAccepted() {
		return accepted;
	}

	public boolean isDeleted() {
		return deleted;
	}

	public String getCause() {
		return cause;
	}

	public void setEstate(Estate estate) {
		this.estate = estate;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public User getUser() {
		return user;
	}

	public Estate getEstate() {
		return estate;
	}

	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}

	public void setAccepted(boolean accepted) {
		this.accepted = accepted;
	}
	public void setCause(String cause) {
		this.cause = cause;
	}
}
